import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";

import typedocSidebar from "./docs/api/typedoc-sidebar.cjs";

// Something doesn't work when using the TypeDoc sidebar with DateLib importing types from date-fns.
const typedocSidebarFixed = typedocSidebar.map((item) => {
  if (item.label === "Classes") {
    return {
      ...item,
      items: item.items?.map((item) => {
        if (item.label === "DateLib") {
          return {
            type: "doc",
            id: "api/classes/DateLib",
            label: "DateLib",
          };
        }
        return item;
      }),
    };
  }
  return item;
});

const sidebars: SidebarsConfig = {
  docs: [
    "intro",
    "start",
    {
      type: "category",
      label: "Customization",
      collapsed: false,
      items: [
        {
          type: "autogenerated",
          dirName: "docs",
        },
      ],
    },
    {
      type: "category",
      label: "Selecting Days",
      collapsed: false,
      items: [
        {
          type: "autogenerated",
          dirName: "selections",
        },
      ],
    },
    {
      type: "category",
      label: "Localization",
      collapsed: false,
      items: [
        "localization/changing-locale",
        "localization/setting-time-zone",
        "localization/iso-and-broadcast",
        "localization/persian",
        "localization/buddhist",
        "localization/ethiopic",
        "localization/hebrew",
      ],
    },
    {
      type: "category",
      label: "Guides",
      collapsed: false,
      items: [
        {
          type: "autogenerated",
          dirName: "guides",
        },
      ],
    },
    {
      type: "category",
      label: "Development",
      collapsed: true,
      items: [
        {
          type: "autogenerated",
          dirName: "development",
        },
      ],
    },
    "changelog",
    "upgrading",
    "license",
  ],
  api: ["api/index", typedocSidebarFixed],
};

export default sidebars;
